package com.store.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.SendStampsBean;

import java.util.List;

import de.greenrobot.event.EventBus;

public class SendStamps_1Adapter extends BaseAdapter  {
    private Context context;
    ViewHolder viewHolder = null;
    private List<Boolean> list_check;
    public SendStamps_1Adapter(Context contextI, List<Boolean> list_check) {
        this.context = contextI;
        this.list_check=list_check;
    }
    public void setCheckList(List<Boolean> list_check){
        this.list_check=list_check;
    }
    @Override
    public int getCount() {
        return 5;
    }

    @Override
    public Object getItem(int position) {

        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

//        Log.v("zyl", "适配器遍历");
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_sendstamps, null);
            viewHolder.img_check = (ImageView) convertView.findViewById(R.id.item_sendstamp_check);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.item_sendstamp_title);
            viewHolder.tv_date = (TextView) convertView.findViewById(R.id.item_sendstamp_date);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        boolean ischeck=list_check.get(position);
        if(ischeck){
            viewHolder.img_check.setBackgroundResource(R.drawable.sendstamps_check);
        }else{
            viewHolder.img_check.setBackgroundResource(R.drawable.sendstamps_nocheck);
        }
        viewHolder.img_check.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean ischeck=list_check.get(position);
                if(ischeck){
                    EventBus.getDefault().post(new SendStampsBean(position,false));
                }else{
                    EventBus.getDefault().post(new SendStampsBean(position,true));
                }
            }
        });


        return convertView;
    }


    class ViewHolder {
       private ImageView img_check;
       private TextView tv_title;
       private TextView tv_date;

    }


}
